package com.gather.spring.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @author kxd
 * @date 2018/12/4 19:46
 * description:
 */
@Service
@Slf4j
public class RemoteService {
    @Retryable(value = RuntimeException.class,
            maxAttempts = 3, backoff = @Backoff(delay = 5000L, multiplier = 2))

    public void call() {
        log.info("call something...");
        throw new RuntimeException("RPC调用异常");
    }

    /**
     * recover机制
     */
    @Recover
    public void recover(RuntimeException e) {
        log.info(" start do recover things...");
        log.warn("we meet ex:", e);
    }
}
